package com.bawei.module_goods.ui.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bawei.module_goods.R

class HistoryAdapter(
    private val onItemClick: (String) -> Unit
) : RecyclerView.Adapter<HistoryAdapter.ViewHolder>() {
    private var data: List<String> = emptyList()
    fun submitList(list: List<String>) {
        data = list
        notifyDataSetChanged()
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_history, parent, false)
        return ViewHolder(view)
    }
    override fun getItemCount() = data.size
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val keyword = data[position]
        holder.tvHistory.text = keyword
        holder.itemView.setOnClickListener { onItemClick(keyword) }
    }
    class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val tvHistory: TextView = view.findViewById(R.id.tv_history)
    }
} 